﻿#include "UserRegisterCodec.h"

#include "TcpCodec.h"

#include "qdebug.h"

UserRegisterCodec::UserRegisterCodec()
{
  setObjectName(getClassNameFirstLow<UserRegisterCodec>());
}

UserRegisterCodec::~UserRegisterCodec()
{
}

void UserRegisterCodec::login(QString userName,QString password)
{
  tcpCodec->code(TcpCodec::Register,
                 QByteArray().append(UserRegisterCodec::Register,1)
                             .append(userNameFlag)
                             .append(userName.toUtf8())
                             .append(passwordFlag)
                             .append(password.toUtf8()));
}

void UserRegisterCodec::logout()
{
  tcpCodec->code(TcpCodec::Register,QByteArray().append(UserRegisterCodec::Unregister));
  emit signal_registerState(UserRegisterCodec::Unregister);
}

void UserRegisterCodec::decode(QByteArray data)
{
  if(data.isEmpty())
    {
      return ;
    }
  uchar dataType=data[0];
  if(RegisterType::Size<=dataType)
    {
      return;
    }
  emit signal_registerState(dataType);
}

TcpCodec* UserRegisterCodec::getTcpCodec()const
{
  return tcpCodec;
}

UserRegisterCodec* UserRegisterCodec::setTcpCodec(TcpCodec*const tcpCodec)
{
  this->tcpCodec=tcpCodec;
  printInjection(this,tcpCodec);
  return this;
}

void UserRegisterCodec::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setTcpCodec(getObjFromMap<TcpCodec>(objMap));
}
